﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>参数设置</title>
    <link href="~/ui/lib/theme-chalk/index.css" rel="stylesheet" />
    <script src="~/ui/vue.min.js"></script>
    <script src="~/ui/lib/index.js"></script>
    <script src="~/ui/polyfill.min.js"></script>
    <script src="~/ui/axios.js"></script>
    <style>
        html, body {
            padding: 0;
            margin: 0;
            height: 100%;
        }

        #app {
            height: 100%;
            width: 100%;
            overflow-x: hidden;
            overflow-y:auto;
        }

        .el-card__header, .el-card__body {
            padding:10px;
        }
    </style>
</head>
<body>
    <div id="app">
        <el-row :gutter="20">
            <el-col :span="24">
                <el-card>
                    <div slot="header" style="height:40px;display: flex;align-items: center;justify-content: space-between;">
                        <span>串口设置</span>
                        <span>
                            <el-button type="primary" icon="el-icon-check" v-on:click="saveCemsSerialInfo">保存</el-button>
                            <el-button type="success" icon="el-icon-refresh" v-on:click="queryCemsSerialInfo">刷新</el-button>
                        </span>
                    </div>
                    <el-form ref="cemsSerialInfoRef" :model="cemsSerialInfo" :inline="true">
                        <el-form-item label="串口名称" prop="portName">
                            <el-input v-model="cemsSerialInfo.portName" />
                        </el-form-item>
                        <el-form-item label="波特率" prop="baudRate">
                            <el-input v-model.number="cemsSerialInfo.baudRate" />
                        </el-form-item>
                        <el-form-item label="数据位" prop="dataBits">
                            <el-input v-model.number="cemsSerialInfo.dataBits" />
                        </el-form-item>
                        <el-form-item label="校验方式" prop="parity">
                            <el-select v-model="cemsSerialInfo.parity" placeholder="请选择校验方式" style="width:100%;">
                                <el-option label="无校验" :value="0"></el-option>
                                <el-option label="奇校验" :value="1"></el-option>
                                <el-option label="偶校验" :value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="停止位" prop="stopBits">
                            <el-input v-model.number="cemsSerialInfo.stopBits" placeholder="请输入停止位" clearable />
                        </el-form-item>
                    </el-form>
                </el-card>
            </el-col>
            <el-col :span="24">
                <el-card style="margin-top:5px;">
                    <div slot="header" style="height:40px;display: flex;align-items: center;justify-content: space-between;">
                        <span>网口设置</span>
                        <span>
                            <el-button type="primary" v-on:click="saveLocalDevice">保存</el-button>
                            <el-button type="primary" v-on:click="saveNetWorkInfo">保存网口数量</el-button>
                            <el-button type="success" v-on:click="refreshNetWorkInfo">刷新网口数量</el-button>
                            @* <el-button type="success" v-on:click="refreshLocalDevice">刷新</el-button> *@
                        </span>
                    </div>
                    <el-form ref="localDeviceRef" :model="localDeviceInfo" label-width="110px" :inline="true">
                        <el-form-item label="网口数量">
                            <el-input v-model="netWorkNumber" />
                        </el-form-item>
                        <el-form-item label="网口ID" prop="id">
                            <el-select v-model="localDeviceInfo.id" placeholder="请选择网口ID" style="width:100%;" v-on:change="handleChange">
                                <el-option v-for="item in netWorkNumber" :key="item" :label="item" :value="item"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="网络IP" prop="ip">
                            <el-input v-model="localDeviceInfo.ip" />
                        </el-form-item>
                        <el-form-item label="网关" prop="gateWay">
                            <el-input v-model="localDeviceInfo.gateWay" />
                        </el-form-item>
                        <el-form-item label="子网掩码" prop="mask">
                            <el-input v-model="localDeviceInfo.mask" />
                        </el-form-item>
                        <el-form-item label="路由IP" prop="routeIP">
                            <el-input v-model="localDeviceInfo.routeIP" />
                        </el-form-item>
                        <el-form-item label="路由网关" prop="routeGateWay">
                            <el-input v-model="localDeviceInfo.routeGateWay" />
                        </el-form-item>
                        <el-form-item label="路由子网掩码" prop="routeMask">
                            <el-input v-model="localDeviceInfo.routeMask" />
                        </el-form-item>
                    </el-form>
                </el-card>
            </el-col>
            <el-col :span="12">
                <el-card style="margin-top:5px;">
                    <div slot="header" style="height:40px;display: flex;align-items: center;justify-content: space-between;">
                        <span>设备信息</span>
                        <span>
                            <el-button type="primary" v-on:click="saveDevice">保存</el-button>
                            <el-button type="success" v-on:click="refreshDevice">刷新</el-button>
                            <el-button type="success" v-on:click="reboot">设备重启</el-button>
                        </span>
                    </div>
                    <el-form ref="localDeviceRef" :model="deviceInfo" :inline="true">
                        <el-form-item label="设备id" prop="deciceIds">
                            <el-input v-model="deviceInfo.deciceIds" />
                        </el-form-item>
                        <el-form-item label="间隔时间" prop="interval">
                            <el-input v-model="deviceInfo.interval" />
                        </el-form-item>
                    </el-form>
                </el-card>
            </el-col>
            <el-col :span="12">
                <el-card style="margin-top:5px;">
                    <div slot="header" style="height:40px;display: flex;align-items: center;justify-content: space-between;">
                        <span>平台信息设置</span>
                        <span>
                            <el-button type="primary" v-on:click="savePlateFormInfo">保存</el-button>
                            <el-button type="success" v-on:click="refreshPlateFormInfo">刷新</el-button>
                        </span>
                    </div>
                    <el-form ref="plateFormInfoRef" :model="plateFormInfo" label-width="110px" :inline="true">
                        <el-form-item label="网络IP" prop="serverIP">
                            <el-input v-model="plateFormInfo.serverIP" />
                        </el-form-item>
                        <el-form-item label="网关" prop="serverPort">
                            <el-input v-model="plateFormInfo.serverPort" />
                        </el-form-item>
                    </el-form>
                </el-card>
            </el-col>
        </el-row>

    </div>

    <script>
        var vm = new Vue({
            el: '#app',
            data: function () {
                return {
                   cemsSerialInfo:{},
                   localDeviceInfo:{},
                   netWorkNumber:0,
                   deviceInfo:{},
                   plateFormInfo:{}
                }
            },
            created(){
                this.queryCemsSerialInfo()
                this.refreshNetWorkInfo()
                this.refreshDevice()
                this.refreshPlateFormInfo()
            },
            methods: {
                saveCemsSerialInfo(){
                    axios({
                        method: 'post',
                        url: '/api/Config/UpdateSerialConfig',
                        data:this.cemsSerialInfo
                        }).then(res => {
                            if (res.data.errcode !== 0) return this.$message.error(res.data.errmsg)
                            this.$message.success('设置成功')
                    })
                },

                queryCemsSerialInfo(){
                    axios({
                        method: 'post',
                        url: '/api/Config/QueryCemsSerialInfo',
                        }).then(res => {
                            if (res.data.errcode !== 0) return this.$message.error(res.data.errmsg)
                            this.cemsSerialInfo = res.data.data
                        })
                },

                saveLocalDevice(){
                    axios({
                        method: 'post',
                        url: '/api/NetWork/UpdateNetInfo',
                        data:this.localDeviceInfo
                        }).then(res => {
                            if (res.data.errcode !== 0) return this.$message.error(res.data.errmsg)
                            this.$message.success('设置成功')
                    })
                },
                handleChange(id){
                     axios({
                        method: 'post',
                        url: '/api/NetWork/QueryNetInfo',
                        data:{id: id}
                        }).then(res => {
                            if (res.data.errcode !== 0) return this.$message.error(res.data.errmsg)
                            this.localDeviceInfo = res.data.data
                        })
                },

                saveNetWorkInfo(){
                     axios({
                        method: 'Post',
                        url: '/api/NetWork/UpdateNetNum',
                        params:{ num: parseInt(this.netWorkNumber) }
                        }).then(res => {
                            if (res.data.errcode !== 0) return this.$message.error(res.data.errmsg)
                            this.$message.success('设置成功')
                            this.refreshNetWorkInfo()
                    })
                },
                refreshNetWorkInfo(){
                    axios({
                        method: 'post',
                        url: '/api/NetWork/QueryNetNum',
                        }).then(res => {
                            if (res.data.errcode !== 0) return this.$message.error(res.data.errmsg)
                            this.netWorkNumber = res.data.data
                        })
                },


                saveDevice(){
                    axios({
                        method: 'post',
                        url: '/api/Config/UpdateDeviceInfo',
                        data:this.deviceInfo
                        }).then(res => {
                            if (res.data.errcode !== 0) return this.$message.error(res.data.errmsg)
                            this.$message.success('设置成功')
                    })
                },
                refreshDevice(){
                    axios({
                        method: 'post',
                        url: '/api/Config/QueryDeviceInfo',
                        }).then(res => {
                            if (res.data.errcode !== 0) return this.$message.error(res.data.errmsg)
                            this.deviceInfo = res.data.data
                        })
                },

                reboot(){
                    axios({
                        method: 'post',
                        url: '/api/NetWork/Reboot',
                        }).then(res => {
                            if (res.data.errcode !== 0) return this.$message.error(res.data.errmsg)
                            this.$message.success('设备重启成功')
                        })
                },

                savePlateFormInfo(){
                    axios({
                        method: 'post',
                        url: '/api/Config/UpdatePlatformInfo',
                        data:this.plateFormInfo
                        }).then(res => {
                            if (res.data.errcode !== 0) return this.$message.error(res.data.errmsg)
                            this.$message.success('修改成功')
                        })
                },
                refreshPlateFormInfo(){
                    axios({
                        method: 'post',
                        url: '/api/Config/QueryPlatformInfo',
                        }).then(res => {
                            if (res.data.errcode !== 0) return this.$message.error(res.data.errmsg)
                           this.plateFormInfo = res.data.data
                        })
                },
            }
        });
    </script>
</body>
</html>
